import Radio from "ant-design-vue/es/radio";
import "ant-design-vue/lib/radio/style/css";

const { Group } = Radio;

export default {
  name: "FormRadioGroup",
  props: {
    option: {
      type: Object,
      default() {
        return {};
      }
    },
    value: [String, Array]
  },
  model: {
    prop: "value",
    event: "updata"
  },
  data() {
    return {
      isFocus: false,
      data: []
    };
  },
  created() {
    if (this.option.data) {
      this.setData(this.option.data);
    }
  },

  methods: {
    onChange(value) {
      this.$emit("updata", value);
      this.$emit("change", value);
    },
    setFocus(is) {
      if (is) {
        this.$refs.formInput.focus();
      } else {
        this.$refs.formInput.blur();
      }
    },
    setData(data) {
      this.data = data;
    }
  },
  render() {
    const that = this;
    const props = {
      ref: "formInput",
      props: {
        ...this.option.props,
        options: this.data,
        value: this.value ? this.value : []
      },
      on: {
        change: e => {
          that.onChange(e);
        },
        focus: e => {
          this.$emit("focus", e);
        },
        blur: e => {
          this.isFocus = false;
          this.$emit("blur", e);
        }
      }
    };

    return <Group {...props} />;
  }
};
